import XtxConfirm from './confirm.vue'
import { h, render } from 'vue'

// 准备container容器，存放弹层元素
const div = document.createElement('div')
div.setAttribute('class', 'xtx-confirm-container')
document.body.appendChild(div)

type ParamsType = {
  text: string,
  title: string
}
export default function Confirm({ text, title }: ParamsType) {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      render(null, div)
      resolve(undefined)
    }
    const cancelCallback = () => {
      render(null, div)
      reject(undefined)
    }
    // 1.创建虚拟dom h(某组件，标签属性，子节点)
    const vNode = h(XtxConfirm, { text, title, confirmCallback, cancelCallback })
    // 2.动态render到容器中
    render(vNode, div)
  })

}